﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Sql;
using sgsBase;
 
namespace wfTree
{
	[Serializable] public class DbFtPerson :  DbObject
	{
	  public DbFtPerson() : base()
	  {
		  Table = "dbo.ft_persons";
		  Database = "sgs_core";
		  Columns.AddColumn("person_id", SqlDbType.BigInt, true, true);
		  Columns.AddColumn("first_name", SqlDbType.VarChar);
		  Columns.AddColumn("last_name", SqlDbType.VarChar);
		  Columns.AddColumn("middle_name", SqlDbType.VarChar);
		  Columns.AddColumn("gender", SqlDbType.Int);
		  Columns.AddColumn("dt_birth", SqlDbType.Date);
		  Columns.AddColumn("dt_death", SqlDbType.Date);
		  Columns.AddColumn("father_person_id", SqlDbType.BigInt);
		  Columns.AddColumn("mother_person_id", SqlDbType.BigInt);
		  Columns.AddColumn("spouse_person_id", SqlDbType.BigInt);
		  Columns.AddColumn("status", SqlDbType.Int);
	  }
  
	  #region Properties
  
		public long PersonId
		{
			get { return Columns.LongAt(0);}
			set { Columns.SetValAt(0, value);}
		}

		public String FirstName
		{
			get { return Columns.StringAt(1);}
			set { Columns.SetValAt(1, value);}
		}

		public String LastName
		{
			get { return Columns.StringAt(2);}
			set { Columns.SetValAt(2, value);}
		}

		public String MiddleName
		{
			get { return Columns.StringAt(3);}
			set { Columns.SetValAt(3, value);}
		}

		public int Gender
		{
			get { return Columns.IntAt(4);}
			set { Columns.SetValAt(4, value);}
		}

		public DateTime DtBirth
		{
			get { return Columns.DateAt(5);}
			set { Columns.SetValAt(5, value);}
		}

		public DateTime DtDeath
		{
			get { return Columns.DateAt(6);}
			set { Columns.SetValAt(6, value);}
		}

		public long FatherPersonId
		{
			get { return Columns.LongAt(7);}
			set { Columns.SetValAt(7, value);}
		}

		public long MotherPersonId
		{
			get { return Columns.LongAt(8);}
			set { Columns.SetValAt(8, value);}
		}

		public long SpousePersonId
		{
			get { return Columns.LongAt(9);}
			set { Columns.SetValAt(9, value);}
		}

		public int Status
		{
			get { return Columns.IntAt(10);}
			set { Columns.SetValAt(10, value);}
		}

	  #endregion

		public string ShortName
		{
			get
			{
				return FirstName + " " + LastName;
			}
		}

		public DbFtPerson GetSiblings()
		{
			DbFtPerson siblings = new DbFtPerson();
			siblings.WhereClause = "person_id!=" + PersonId + " and (father_person_id=" + FatherPersonId + " or mother_person_id=" + MotherPersonId + ")";
			siblings.Select();

			return siblings;
		}

		public DbFtPerson GetChildren()
		{
			DbFtPerson children = new DbFtPerson();
			children.WhereClause = "person_id!=" + PersonId + " and (father_person_id=" + PersonId + " or mother_person_id=" + PersonId + ")";
			children.Select();

			return children;

		}
	}
}
